﻿#include "stdafx.h"
#include "canvas.h"

void draw::Square(int x, int y, int width, int height, int color)
{
	Line(x, y, x + width - 1, y, color);
	Line(x, y, x, y + height - 1, color);
	Line(x + width - 1, y, x + width - 1, y + height - 1, color);
	Line(x, y + height - 1, x + width - 1, y + height - 1, color);
}

void draw::Line(int fx, int fy, int lx, int ly, int color)
{
	SetConsoleTextAttribute(hOut, color);
	COORD pos{ (short)fx,(short)fy };
	while (pos.X != lx || pos.Y != ly)
	{
		SetConsoleCursorPosition(hOut, pos);
		printf(" ");
		if (pos.X != lx)
		{
			pos.X += (lx - pos.X) / abs(pos.X - lx);
		};
		if (pos.Y != ly)
		{
			pos.Y += (ly - pos.Y) / abs(pos.Y - ly);
		};
	}
	SetConsoleCursorPosition(hOut, pos);
	printf(" ");
	SetConsoleTextAttribute(hOut, default_color);
}